import axios from 'axios';

/**
 * 初始结构
 */
const initialState = {
  formRecord: { a: 0, b: 0 }, // 表单数据（被加数，加数）
  result: 0, // 运算结果（求和）
  modalShow: false, // 展示模态框
};

export default {
  namespace: 'lvchanglong', // namespace: namespace

  state: initialState,

  effects: {
    *random({ payload }, { call, put }) {
      const res = yield call(axios.get, `/api/random`, { params: payload });
      console.log(res.data);
      yield put({ type: 'save', payload: res.data });
    },

    *plus({ payload }, { call, put }) {
      const res = yield call(axios.post, `/api/plus`, payload);
      console.log(res.data);
      yield put({ type: `save`, payload: res.data });
    },
  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
  },
};
